<?php
	/*
		Form element = http://www.w3.org/TR/2011/WD-html5-20110525/forms.html#the-form-element
	*/

	class PookiHTMLForm extends PookiHTMLElement
	{
		public 			$name;
		public			$internal_name;
		public 			$novalidate = FALSE;
		public			$session_token;
		
		private 		$controls = array();
		private 		$action;
		private 		$autocomplete = TRUE;
		
		protected 		$enctype = "application/x-www-form-urlencoded";
		protected 		$acceptCharset = "UTF-8";
		protected 		$method = "POST";
		protected 		$target = "index.pooki";

		public function setAttributes()
		{
				$this->setBaseAttributes();
				
				$base_attributes = array(
					"enctype" => $this->enctype,
					"accept-charset" => $this->acceptCharset, 
					"method" => $this->method,
					"target" => $this->target
				);
				$this->attributes = array_merge($this->attributes,$base_attributes);
		}
		
		public function __construct()
		{
			$this->unsettable_variables = array_merge(array(
				"attributes",
				"unique_id",
				"secure_name",
			),$this->unsettable_variables);
		
			$this->setAttributes();
		}
	}

	class PookiFormControl
	{
		protected $type;
		protected $output_html;
		
		static $form_element_types = array(
				POOKI_FORM_BUTTON => "button",
				POOKI_FORM_CHECKBOX => "checkbox",
				POOKI_FORM_CHECKBOXES => "checkboxes",
				POOKI_FORM_COLOR => "color",
				POOKI_FORM_DATETIME => "datetime",
				POOKI_FORM_DATETIME_LOCAL => "datetime_local",
				POOKI_FORM_EMAIL_ADDRESS => "email",
				POOKI_FORM_FILE => "file",
				POOKI_FORM_FIELDSET => "fieldset",
				POOKI_FORM_HIDDEN => "hidden",
				POOKI_FORM_IMAGE => "image",
				POOKI_FORM_LABEL => "label",
				POOKI_FORM_MONTH => "month",
				POOKI_FORM_NUMBER => "number",
				POOKI_FORM_OPTION => "option",
				POOKI_FORM_OPTGROUP => "optgroup",
				POOKI_FORM_PASSWORD => "password",
				POOKI_FORM_RADIO => "radio",
				POOKI_FORM_RADIOS => "radios",
				POOKI_FORM_RANGE => "range",
				POOKI_FORM_RESET => "reset",
				POOKI_FORM_SEARCH => "search",
				POOKI_FORM_SUBMIT => "submit",
				POOKI_FORM_TELEPHONE_NUMBER => "telephone_number",
				POOKI_FORM_TEXT => "text",
				POOKI_FORM_TEXTAREA => "textarea",
				POOKI_FORM_TIME => "time",
				POOKI_FORM_URL => "url",
				POOKI_FORM_WEEK => "week"
		);

		protected function initRenderFunction($element_type,$func_args)
		{
				switch($element_type)
				{
					case "button":
					case "checkbox":
					case "checkboxes":
					case "color":
					case "datetime":
					case "datetime_local":
					case "email":
					case "file":
					case "fieldset":
					case "hidden":
					case "image":
					case "label":
					case "month":
					case "number":
					case "option":
					case "optgroup":	
					case "password":
					case "radio":
					case "radios":
					case "range":
					case "reset":
					case "search":
					case "submit":
					case "telephone_number":
					case "text":
					case "textarea":
					case "time":
					case "url":
					case "week":
				}
		}
		
		public function __construct($pooki_form_type) 
		{
			$elements = array_keys(PookiFormControl::$form_element_types);
			
			if(in_array($pooki_form_type,$elements))
			{
				$element_type = PookiFormControl::$form_element_types[$pooki_form_type];
				$arguments = func_get_args();
				
				$this->initRenderFunction($element_type,$arguments);
			}
			
		}
		
		
	}
	
	class PookiHTMLFormGenerator
	{

		
		protected function generateInternalName($form_name)
		{
			if(substr_count($form_name,"pooki_forms_") >=1)
			{
				$name = str_replace("pooki_forms_","",$form_name);
				if($name == "")
				{
					$name = "unnamed_" . mt_rand();
				}
			}
			return "pooki_forms_" . $form_name;
		}
		
		protected function generateSessionToken()
		{
			return uniqid(null,true);
		}
		
		public function __construct()
		{
			$form = new PookiHTMLForm();
			$form->internal_name = $this->generateInternalName();
			$form->session_token = $this->generateSessionToken();
		}
		
		public function addControl(PookiFormControl $control)
		{
			
		}
	}
?>